/* 
 *  Copyright (C) 2006 Dip. Ing. dell'Informazione, University of Pisa, Italy
 *  http://info.iet.unipi.it/~cng/ns2measure/ns2measure.html
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, USA
 */

/**
   project: measure
   filename: main.cc
	author: C. Cicconetti <c.cicconetti@iet.unipi.it>
	year: 2006
   affiliation:
      Dipartimento di Ingegneria dell'Informazione
	   University of Pisa, Italy
   description:
	   Analyze utility.
*/

#include <config.h>
#include <measure.h>
#include <input.h>
#include <output.h>

#include <cstdlib>

#include <iostream>
#include <string>

using namespace std;

int
main (int argc, char* argv[]) {

	if ( argc <= 1 ) {
		cout << "usage: " << argv[0] << " config [input [output]]\n"
			<< "\nif 'input' (or 'output') is not given, /dev/null is used\n";
		exit (0);
	}
	
	string configFileName (argv[1]);
	string inputFileName;
	string outputFileName;

	if ( argc == 2 ) {
		inputFileName = "/dev/null";
		outputFileName = "/dev/null";
	} else if ( argc == 3 ) {
		inputFileName = argv[2];
		outputFileName = "/dev/null";
	} else {
		inputFileName = argv[2];
		outputFileName = argv[3];
	}

	try {
		Configuration conf;
		conf.parse (configFileName);

		Metrics metrics;
		Input input (conf, metrics);
		input.loadData (inputFileName, outputFileName);
		Output output (conf, metrics);
		output.generate ();

	} catch (Object& obj) {
		cerr << "Exception raised by the instance #" << obj.getId()
			<< " of class " << obj.getName() << ". Terminated.\n";
	}

	exit (1);
}
